using System;
using System.Collections.Generic;

namespace TDUnit.Common.TestData
{
    public class TestData
    {
        private readonly List<Table> _tables = new List<Table>();

        public Table[] Tables
        {
            get { return _tables.ToArray(); }
        }

        public Table GetTable(string name)
        {
            foreach(var t in _tables)
            {
                if(t.Name.Equals(name) || t.Alias.Equals(name))
                    return t;
            }
            return null;
        }

        public Table AddTable(string name, string primaryKeyColumnName)
        {
            return AddTable(name, primaryKeyColumnName, string.Empty);
        }

        public Table AddTable(string name, string primaryKeyColumnName, string alias)
        {
            var table = new Table(name, primaryKeyColumnName, this, alias);
            if (_tables.Contains(table))
                throw new InvalidOperationException(string.Format("A table with name '{0}' already exists in the dataset.", name));

            _tables.Add(table);
            return table;
        }
    }
}